#include "../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>

zlrmq::MsgQueueManager::ptr emp;

class QueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = std::make_shared<zlrmq::MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        emp->clear();
    }
};

TEST(queue_test, insert_test)
{
    std::unordered_map<std::string, std::string> map = {{"k1", "v1"}, {"k2", "v2"}};
    emp->declareQueue("queue1", true, true, false, map);
    emp->declareQueue("queue2", true, true, false, map);
    emp->declareQueue("queue3", true, true, false, map);
    emp->declareQueue("queue4", true, true, false, map);
    emp->declareQueue("queue5", true, true, false, map);
    ASSERT_EQ(emp->size(), 5);
}

TEST(queue_test, remove_test)
{

    emp->deleteQueue("queue3");
    ASSERT_EQ(emp->exists("queue3"), false);
}

TEST(exchange_test, select_test)
{
    std::unordered_map<std::string, std::string> map = {{"k1", "v1"}, {"k2", "v2"}};
    auto exp = emp->selectQueue("queue4");
    ASSERT_EQ(exp->name, "queue4");
    ASSERT_EQ(exp->durable, true);
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new QueueTest);
    int ret = RUN_ALL_TESTS();
    (void)ret;
    return 0;
}